package com.chinadci.smartcommunitysystembackstage.controller;


import com.chinadci.smartcommunitysystembackstage.entity.ScsVisitor;
import com.chinadci.smartcommunitysystembackstage.service.ScsActivityService;
import com.chinadci.smartcommunitysystembackstage.service.ScsUserService;
import com.chinadci.smartcommunitysystembackstage.service.ScsVisitorService;
import com.chinadci.smartcommunitysystembackstage.util.DateTime;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.bytebuddy.description.NamedElement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Code Duck
 * @since 2021-04-13
 */
@CrossOrigin
@RestController
@Api("建业E家")
public class ScsVisitorController {
    @Autowired
    private ScsVisitorService service;

    @Autowired
    private ScsUserService user;

    //显示访客记录
    @ApiOperation(value = "显示访客记录")           //swagger
    @ApiImplicitParam(name = "name",value = "访客姓名")       //表明要传入的参数
    @RequestMapping(value = "/api/xsfk",method = RequestMethod.GET)
    public Map Finds(String name){
        Map<String,Object> map=new HashMap<>();
        map.put("data",service.Find(name));
        return map;
    }

    //访客登记
    @ApiOperation(value = "访客登记")           //swagger
    @ApiImplicitParam(name = "ScsVisitor",value = "对象")       //表明要传入的参数
    @RequestMapping(value = "/api/fkdj",method = RequestMethod.POST)
    public Map Insert(ScsVisitor scs){
        Map<String,Object> map=new HashMap<>();
        if (user.Finds(scs.getName())==null){
            map.put("name",0);      //name为0说明没有那个业主
            return map;
        }
        scs.setVTime(DateTime.GetTime());
        scs.setUId(user.Finds(scs.getName()).getUId());
        map.put("name",0);      //name为1说明有那个业主
        map.put("data",service.Insert(scs));
        return map;
    }
}
